package org.example.util;

import org.example.service.imp.TicketServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@Component
public class CookieUtil {
    @Autowired
    private HutoolUtil hutoolUtil;
    @Autowired
    private TicketServiceImp ticketServiceImp;
    @Value("${server.servlet.context-path}")
    private String communityPath;

    public void deleteTicket(String ticket, HttpServletResponse response){
        if (!hutoolUtil.stringIsEmpty(ticket)){
            ticketServiceImp.deleteTicketByTicket(ticket);
            Cookie cookie = new Cookie(CommonParam.TICKET_SYMBOL,ticket);
            cookie.setMaxAge(0);
            cookie.setPath(communityPath+"/");
            response.addCookie(cookie);

        }
    }
}
